﻿//#include <iostream>
//
//int main()
//{
//    std::cout << "Hello World!\n";
//}


// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp : public wxApp
{
public:
	virtual bool OnInit();
};



class MyFrame : public wxFrame
{
public:
	MyFrame();

private:
	void OnHello(wxCommandEvent& event);
	void OnExit(wxCommandEvent& event);
	void OnAbout(wxCommandEvent& event);
	void OnTest(wxCommandEvent& event);
};



enum
{
	ID_Hello = 1,
	Test_Hello = 2,
	ID_BUTTON1,
	ID_BUTTON2,
	ID_BUTTON3,
	ID_BUTTON4,
	ID_BUTTON5,
	ID_BUTTON6,
};


wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
	MyFrame* frame = new MyFrame();
	frame->Show(true);
	return true;
}



MyFrame::MyFrame()	: wxFrame(NULL, wxID_ANY, "Hello World")
{
	wxMenu* menuFile = new wxMenu;
	menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
		"Help string shown in status bar for this menu item");
	menuFile->AppendSeparator();
	menuFile->Append(wxID_EXIT);

	wxMenu* menuHelp = new wxMenu;
	menuHelp->Append(wxID_ABOUT);

	//新增一个菜单
	wxMenu* test = new wxMenu;
	test->Append(Test_Hello,"测试菜单","这是一个测试菜单");

	wxMenuBar* menuBar = new wxMenuBar;
	menuBar->Append(menuFile, "&File");
	menuBar->Append(menuHelp, "&Help");
	menuBar->Append(test, "&Test");

	SetMenuBar(menuBar);
	CreateStatusBar();
	SetStatusText("Welcome to wxWidgets!");
	Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
	Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
	Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
	Bind(wxEVT_MENU, &MyFrame::OnTest, this, Test_Hello);

	//创建一个复杂网格布局控件
	wxFlexGridSizer* flexGridSizer = new wxFlexGridSizer(2, 3, 0, 0);
	this->SetSizer(flexGridSizer);
	//让第一列可变大小
	flexGridSizer->AddGrowableCol(0);
	wxButton* button1 = new wxButton(this, ID_BUTTON1, wxT("One"));
	flexGridSizer->Add(button1, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	wxButton* button2 = new wxButton(this, ID_BUTTON2, wxT("Two (the second button)"));
	flexGridSizer->Add(button2, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	wxButton* button3 = new wxButton(this, ID_BUTTON3, wxT("Three"));
	flexGridSizer->Add(button3, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	wxButton* button4 = new wxButton(this, ID_BUTTON4, wxT("Four"));
	flexGridSizer->Add(button4, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	wxButton* button5 = new wxButton(this, ID_BUTTON5, wxT("Five"));
	flexGridSizer->Add(button5, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	wxButton* button6 = new wxButton(this, ID_BUTTON6, wxT("Six"));
	flexGridSizer->Add(button6, 0, wxALIGN_CENTER_HORIZONTAL |
		wxALIGN_CENTER_VERTICAL | wxALL, 5);
	flexGridSizer->Fit(this);
	flexGridSizer->SetSizeHints(this);
}




void MyFrame::OnExit(wxCommandEvent& event)
{
	Close(true);
}



void MyFrame::OnAbout(wxCommandEvent& event)
{
	wxMessageBox("This is a wxWidgets Hello World example",
		"About Hello World", wxOK | wxICON_INFORMATION);
}




void MyFrame::OnHello(wxCommandEvent& event)
{
	wxLogMessage("Hello world from wxWidgets!");
}




void MyFrame::OnTest(wxCommandEvent& event)
{
	wxLogMessage("你点击了测试按钮!");
	
}
